package com.example.fzj.hazelcast.account.controller;

import com.example.fzj.hazelcast.account.domain.ReqCase;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

/**
 * @Author fanzj
 * @Date 2021/8/15 4:29 下午
 * @Version 3.0
 * @Description login-web
 */
@Controller
public class AccountController {

    @PostMapping("/login")
    public String login(ReqCase reqCase){
        reqCase.setAccountName("admin");
        reqCase.setAccPwd("bonree");
        UsernamePasswordToken passwordToken=new UsernamePasswordToken(reqCase.getAccountName(), reqCase.getAccPwd());
        Subject subject = SecurityUtils.getSubject();
        // TODO try catch
        subject.login(passwordToken);
        return  "redirect:/success";
    }

    @GetMapping("/login")
    public String login(){
        Subject subject = SecurityUtils.getSubject();
        boolean authenticated = subject.isAuthenticated();
        if(authenticated){
            return  "success.html";
        }else{
            return  "login.html";
        }
    }

}
